<?php
echo $this->Html->script('chosen.jquery.min');
echo $this->Html->script('data');
echo $this->Html->script('ueditor/ueditor.all.min');
echo $this->Html->script('ueditor/ueditor.config');
echo $this->Html->css('postRecipe');
echo $this->Html->css('chosen.min');

?>

<!-- 菜谱发布 -->

<div id="recipeCreate">
  <div id="recipeCreateTitle">新菜谱</div>
  <hr />
  <?php echo $this->element('fileUpload');?>
  <form method="POST" id="newRecipe">
    <input type="hidden" name="data[Recipe][img]" id="imgPath" />
    <div id="addIngredient">
      <div>食材</div>
      <hr>
      <input type="hidden" name="data[Recipe][ingredient0]" id="ingredient0" value=""/>
      <input type="hidden" name="data[Recipe][ingredient1]" id="ingredient1" value=""/>
      <input type="hidden" name="data[Recipe][ingredient2]" id="ingredient2" value=""/>
      <div class="addType">主料：<select data-placeholder="请选择主料" multiple id="addType0"></select></div>
      <div class="addType">辅料：<select data-placeholder="请选择辅料" multiple id="addType1"></select></div>
      <div class="addType">调料：<select data-placeholder="请选择调料" multiple id="addType2"></select></div>
      <script type="text/javascript">
        ingdt = Array();
        ingdt = searchIngredient("");
        var len = ingdt.length;
        var selectList = "";
        for (var i = 0; i < len ; i++){
          selectList+="<option>"+ingdt[i]+"</option>";
        }

        function searchIndex(key){
          var len = ingdt.length;
          for (var i = 0; i < len; i++) {
            if (ingdt[i] == key) return i;
          };
        }
        function setOption(num){
          var s = $("#ingredient"+num).val().split(' ');
          var s1 = Array();
          for (var i = s.length - 1; i >= 0; i--) {
            s1.push(searchIndex(s[i]));
          };

          var c1 = $("#addType"+num).html(selectList).children('option');
          for (var i = s1.length - 1; i >= 0; i--) {
            c1.eq(s1[i]).attr('selected','true');
          };

          $("#addType"+num).chosen({width: "300px"}).change(function(){
            var str = Array();
            $('#addType'+num+'_chzn span').each(function(){
              str.push($(this).text());
            });
            $("#ingredient"+num).val(str.join(" "));
          });
        }

        function checkImg () {
          if ($("#imgPath").val() == "") {
            alert("必须要有一个成品图！请在页面右上方上传图片。");
            return false;
          }
          return true;
        }

        setOption(0);
        setOption(1);
        setOption(2);
      </script>
    </div>
    <br />
    <label for="recipeName">　　　　菜名：</label><input type="text" id="recipeName" name="data[Recipe][name]" required/><br />
    <label for="tags">标签，空格隔开：</label><input type="text" id="tags" name="data[Recipe][tags]" /><br />

    <label for="method">　　　　工艺：</label>
    <select name="data[Recipe][method]" id="method" class="selectOption">
      <option value="炒">炒</option>
      <option value="蒸">蒸</option>
      <option value="煮">煮</option>
      <option value="炖">炖</option>
      <option value="拌">拌</option>
      <option value="烧">烧</option>
      <option value="煎">煎</option>
      <option value="炸">炸</option>
      <option value="烘焙">烘焙</option>
      <option value="微波">微波</option>
      <option value="烤">烤</option>
      <option value="煲">煲</option>
      <option value="焖">焖</option>
      <option value="冻">冻</option>
      <option value="烙">烙</option>
      <option value="砂锅">砂锅</option>
      <option value="腌">腌</option>
      <option value="卤">卤</option>
      <option value="酱">酱</option>
      <option value="烩">烩</option>
      <option value="扒">扒</option>
      <option value="爆">爆</option>
      <option value="炝">炝</option>
      <option value="熘">熘</option>
      <option value="熏">熏</option>
      <option value="汆">汆</option>
      <option value="拔丝">拔丝</option>
      <option value="榨汁">榨汁</option>
      <option value="灼">灼</option>
      <option value="泡">泡</option>
      <option value="腊">腊</option>
      <option value="糖蘸">糖蘸</option>
      <option value="干锅">干锅</option>
      <option value="焗">焗</option>
      <option value="干煸">干煸</option>
      <option value="煨">煨</option>
      <option value="其他">其他</option>
    </select><br />
    <label for="taste">　　　　口味：</label>
    <select name="data[Recipe][taste]" id="taste" class="selectOption">
      <option value="家常味">家常味</option>
      <option value="香辣味">香辣味</option>
      <option value="咸鲜味">咸鲜味</option>
      <option value="甜味">甜味</option>
      <option value="酸甜味">酸甜味</option>
      <option value="酸辣味">酸辣味</option>
      <option value="麻辣味">麻辣味</option>
      <option value="酱香味">酱香味</option>
      <option value="奶香味">奶香味</option>
      <option value="蒜香味">蒜香味</option>
      <option value="鱼香味">鱼香味</option>
      <option value="葱香味">葱香味</option>
      <option value="果味">果味</option>
      <option value="五香味">五香味</option>
      <option value="咖喱味">咖喱味</option>
      <option value="椒麻味">椒麻味</option>
      <option value="茄汁味">茄汁味</option>
      <option value="酸味">酸味</option>
      <option value="苦香味">苦香味</option>
      <option value="姜汁味">姜汁味</option>
      <option value="怪味">怪味</option>
      <option value="芥末味">芥末味</option>
      <option value="红油味">红油味</option>
      <option value="豆瓣味">豆瓣味</option>
      <option value="麻酱味">麻酱味</option>
      <option value="黑椒味">黑椒味</option>
      <option value="糊辣味">糊辣味</option>
      <option value="其他">其他</option>
    </select><br />
  <label for="difficulty">　　　　难度：</label>
  <select name="data[Recipe][difficulty]" id="difficulty" class="selectOption">
    <option value="0">新手</option>
    <option value="1">初级</option>
    <option value="2">初中</option>
    <option value="3">中级</option>
    <option value="4">高级</option>
    <option value="5">厨神</option>
  </select>
  <br />
  <label for="prepareTime">　　准备时间：</label>
  <select name="data[Recipe][prepareTime]" id="prepareTime" class="selectOption">
    <option value="5分钟">5分钟</option>
    <option value="10分钟">10分钟</option>
    <option value="15分钟">15分钟</option>
    <option value="30分钟">30分钟</option>
    <option value="60分钟">60分钟</option>
    <option value="90分钟">90分钟</option>
    <option value="2小时">2小时</option>
    <option value="数小时">数小时</option>
    <option value="一天">一天</option>
    <option value="数天">数天</option>
  </select><br />
  <label for="cookTime">　　烹饪时间：</label>
  <select name="data[Recipe][cookTime]" id="cookTime" class="selectOption">
    <option value="&lt;5分钟">&lt;5分钟</option>
    <option value="&lt;10分钟">&lt;10分钟</option>
    <option value="&lt;15分钟">&lt;15分钟</option>
    <option value="&lt;30分钟">&lt;30分钟</option>
    <option value="&lt;60分钟">&lt;60分钟</option>
    <option value="&lt;90分钟">&lt;90分钟</option>
    <option value="&lt;2小时">&lt;2小时</option>
    <option value="&lt;数小时">&lt;数小时</option>
    <option value="&lt;一天">&lt;一天</option>
    <option value="&lt;数天">&lt;数天</option>
  </select>
  <br />

  <hr />
  <br />
  <label for="description">描述：</label><br /><textarea required id="descriptionTextarea" id="description" name="data[Recipe][description]"></textarea>
  <br />
  <label for="myEditor">菜谱内容：</label><textarea name="data[Recipe][content]" id="myEditor"><ol style="list-style-type: decimal;"><li><p>第一步</p></li></ol></textarea>
  <script type="text/javascript">
      var editor = new UE.ui.Editor({toolbars:[['fullscreen','bold','|','undo','redo','|','underline','insertorderedlist','insertimage']]});
      editor.render("myEditor");
  </script>
  <br />

  <input type="submit" id="postNewRecipe" value="发布" onclick="return checkImg();"/>
  </form>
  
</div>

</div>